#include <iostream>
using std::cout;
using std::endl;

class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + "
            << _image << "i"
            << endl;
    }

    Complex & operator+=(const Complex & rhs){
        _real += rhs._real;
        _image += rhs._image;
        return *this;
    }

    friend Complex operator+(const Complex & c1,const Complex & c2);
private:
    int _real;
    int _image;
};

//友元函数形式实现重载
Complex operator+(const Complex & c1,const Complex & c2)
{
    return Complex(c1._real + c2._real,
                   c1._image + c2._image);

}

void test0(){
    int a = 1, b = 2;
    cout << &a << endl;
    cout << &(a += b) << endl;
    cout << a << endl;
    cout << b << endl;


    Complex cx1(1,2);
    Complex cx2(3,4);
   
    //本质形式
    /* cx1.operator+=(cx2);//返回cx1 */
    cx1 += cx2;
    cx1.print();
    cx2.print();




}



int main(void){
    test0();
    return 0;
}
